//
// Created by 11510 on 2024/7/17.
//

#ifndef EVENT_PASS2_OUT_H
#define EVENT_PASS2_OUT_H

#include <QDebug>
#include <QEvent>
#include <QLabel>
#include <QMouseEvent>

class Out : public QLabel {
Q_OBJECT
public:
    Out(QWidget *parent = nullptr);

    bool event(QEvent *e) override {
        if (e->type() == QEvent::MouseButtonRelease) {
            qDebug() << objectName() << " " << "event";
        }
        return QLabel::event(e);
    }

    void mouseReleaseEvent(QMouseEvent *ev) override {
        qDebug() << objectName() << " " << "event handler";
    }
};

class Mid : public QLabel {
Q_OBJECT
public:
    Mid(QWidget *parent = nullptr);

    bool event(QEvent *e) override {
        if (e->type() == QEvent::MouseButtonRelease) {
            qDebug() << objectName() << " " << "event";
        }
        return QLabel::event(e);
    }

    void mouseReleaseEvent(QMouseEvent *ev) override {
        qDebug() << objectName() << " " << "event handler";
    }
};

class In : public QLabel {
Q_OBJECT
public:
    In(QWidget *parent = nullptr);

    bool event(QEvent *e) override {
        if (e->type() == QEvent::MouseButtonRelease) {
            qDebug() << objectName() << " " << "event";

#if 1
            return true;    /* true说明本对象处理完事件，不交给父类 */
#endif
#if 2
            return false;   /* false说明本对象没有处理完事件，交给父类 */
#endif
        }
        /* 调父类才会调用handle */
        return QLabel::event(e);
    }

    void mouseReleaseEvent(QMouseEvent *ev) override {
        qDebug() << objectName() << " " << "event handler";
        /* ignore交给父类 */
        ev->ignore();

        /* accept不交给父类 */
//        ev->accept();
    }
};


#endif //EVENT_PASS2_OUT_H
